#include "Accelerate.h"
#include <time.h>

Accelerate::Accelerate(double w, double a, double b)
	:weight(w),c1(a),c2(b)
{}

Accelerate::~Accelerate()
{}

void Accelerate::run(vector<vector<double>>& ve, vector<vector<int>>& current, vector<vector<int>>& pbest, vector<int>& gbest, vector<int>& limit)
{
	int ssize=ve.size();
	for(int i=0;i<ssize;i++)
	{
		for(int j=0;j<current[0].size();j++)
		{
			double rnd1,rnd2;
			srand(clock()); 
			rnd1=(rand()%10);
			srand(clock());
			rnd2=(rand()%10);
			double tmp=weight*ve[i][j]+c1*(rnd1/10)*(pbest[i][j]-current[i][j])+c2*(rnd2/10)*(gbest[j]-current[i][j]);
			if(tmp>0&&tmp>=limit[j])
				ve[i][j]=limit[j]-1;
			else if(tmp<0&&tmp<=0-limit[j])
				ve[i][j]=1-limit[j];
			else 
				ve[i][j]=tmp;
		}
	}
}